<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimini/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>编辑职务</legend>
        </fieldset>
    </div>
    <form id="roles" class="layui-form" action="" method="post">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label">组织部门</label>
                <div class="layui-input-inline">
                    <input id="organ" type="text" name="organ" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input" value="${organization.name}">
                    <input id="organId" type="hidden" name="organId" value="${organization.id}"/>
                    <input type="hidden" name="positionOrganId" value="${positionOrgan.id}"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">职务名称</label>
                <div class="layui-input-inline" style="width: 430px;">
                    <input type="text" name="position" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input" value="${position.position}">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">职务描述</label>
                <div class="layui-input-block" style="width: 430px;">
                    <textarea name="description" lay-verify="required" autocomplete="off" placeholder="请输入内容" class="layui-textarea" >${position.description}</textarea>
                </div>
            </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="editPosition"  >立即提交</button>
            </div>
        </div>
    </form>
</div>
<script src="/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/layuimini/js/lay-config.js" charset="utf-8"></script>

<script>
     layui.use(['customSelect', 'tree','form','jquery'],function () {
        const customSelect = layui.customSelect,
                $ = layui.jquery,
                tree = layui.tree,
                form = layui.form,
                layer = layui.layer;
        form.render();
        //$("#organ").text(${organization.name});

        $.ajax({
            type:'get',
            url:'/organ/tree',
            dataType:'json',
            success:function (res)
            {
                customSelect.render({
                    el: 'organ',
                    data: res,
                    //checkbox: true,
                    type: 'radio',
                    selection:[['${organization.name}']],
                    checked: function (obj) {
                        //$("#organ").text(obj.obj.data.name);
                        //$("#organId").val(obj.obj.data.id);
                        clickTreeNode(obj.obj);
                    }
                }) ;
            }
        });

        function clickTreeNode(obj){
            $("#organ").text(obj.data.name);
            $("#organId").val(obj.data.id);
        }


        form.on('submit(editPosition)',function (data) {
            //layer.alert(JSON.stringify(data.field));
            $.ajax({
                type:'post',
                url:'/position/edit/${position.id}',
                data:JSON.stringify(data.field),  //重点必须为一个变量如：data
                dataType:'json',
                contentType : "application/json",
                success:function(res){
                    //layer.alert(JSON.stringify(res));

                    var index = layer.alert(JSON.stringify(res), {
                        title: '最终的提交信息'
                    });

                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.location.reload();
                    parent.layer.close(iframeIndex);

                },
                error:function(){
                    layer.alert(JSON.stringify('失败'));
                }
            });
            return false;
        });

    });
</script>

</body>
</html>